/**
 * @typedef {ShapeOptions&{
 * imageId:string
 * }} ImageShapeOptions
 */
class ImageShape extends Shape {
  /**
   * @description 图片
   * @readonly
   * @type {HTMLImageElement}
   */
  img;

  /**
   * @description 图片id
   * @readonly
   * @type {string}
   */
  imageId;

  /**
   * @description 构造函数
   * @param {ImageShapeOptions} options
   */
  constructor(options) {
    super(options);
    this.img = document.getElementById(options.imageId);
    this.imageId = options.imageId;
  }

  /**
   * @description 设置imageId
   * @param {string} imageId
   */
  setImageId(imageId) {
    this.img = document.getElementById(imageId);
    this.imageId = imageId;
  }

  draw() {
    this.ctx.drawImage(this.img, this.x, this.y, this.width, this.height);
  }

  /**
   * @description 某个点是否在图形之内
   * @param {number} x
   * @param {number} y
   * @returns {boolean}
   */
  contains(x, y) {
    return (
      x >= this.x &&
      x <= this.x + this.width &&
      y >= this.y &&
      y <= this.y + this.height
    );
  }
}
